package net.tv90.bfmccore.helper;

import net.tv90.bfmccore.event.RibbonGetEvent;
import net.tv90.bfmccore.event.ServiceStarGetEvent;
import net.tv90.bfmccore.game.GameManager;
import net.tv90.bfmccore.slot.Slot;
import net.tv90.bfmccore.util.TempPermission;
import org.bitterorange.flansmodslain.models.PlayerRankUpEvent;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

import static net.tv90.bfmccore.battlepack.Battlepack.playerStoredBattlepack;
import static net.tv90.bfmccore.battlepack.BattlepackItemUtil.getSingleBattlepackItem;
import static net.tv90.bfmccore.game.impl.GunMasterGame.currentSlotList;
import static net.tv90.bfmccore.game.impl.GunMasterGame.playerSlotProgress;
import static net.tv90.bfmccore.game.GameBase.firstFactionList;
import static net.tv90.bfmccore.game.GameBase.secondFactionList;
import static net.tv90.bfmccore.squad.Squad.squadMap;
import static net.tv90.bfmccore.slot.SlotHelper.giveSlot;

public class DebugHelper implements CommandExecutor{
    public static int debugX = -1;
    public static int debugY = -1;

    @Override
    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
        if(label.equals("dbg")){
            if (args[0].equalsIgnoreCase("x")) {
                debugX = Integer.parseInt(args[1]);
            }
            if (args[0].equalsIgnoreCase("y")) {
                debugY = Integer.parseInt(args[1]);
            }
            if (args[0].equalsIgnoreCase("game")) {
                System.out.println(GameManager.getInstance().currentGame);
                System.out.println(GameManager.getInstance().currentGamePool);
                System.out.println(firstFactionList);
                System.out.println(secondFactionList);
            }
            if (args[0].equalsIgnoreCase("hud")) {
                Player p = Bukkit.getPlayerExact(args[1]);
                Bukkit.getServer().getPluginManager().callEvent(new RibbonGetEvent(p, null, "test", "EXP", 5));
                Bukkit.getServer().getPluginManager().callEvent(new ServiceStarGetEvent(p, "Test", 100));
                Bukkit.getServer().getPluginManager().callEvent(new PlayerRankUpEvent(p, 10,"test"));
            }
            if(args[0].equalsIgnoreCase("squad")){
                System.out.println(squadMap);
            }
            if(args[0].equalsIgnoreCase("perm")){
                TempPermission.printAllPerms();
            }
            if(args[0].equalsIgnoreCase("slot")){
                if(!sender.isOp()) return false;
                Player p = Bukkit.getPlayerExact(args[1]);
                int progress = playerSlotProgress.getOrDefault(p,0);
                if(progress >= currentSlotList.size()){
                    GameManager.getInstance().currentGame.subEnemyTicket(p,GameManager.getInstance().currentGame.maxTicket);
                    return false;
                }
                Slot slot = currentSlotList.get(progress);
                giveSlot(p, slot);
                GameManager.getInstance().currentGame.subTicket(p,1);
                progress++;
                playerSlotProgress.put(p,progress);
            }
            if(args[0].equalsIgnoreCase("bp")){

                System.out.println(playerStoredBattlepack);
                if(!sender.isOp()) return false;
                if(sender instanceof Player){
                    getSingleBattlepackItem((Player) sender);
                }
            }
        }
        return false;
    }
}
